package servlet3;

import com.google.gson.Gson;
import dao.DB;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


//模糊查询
@WebServlet("/vagueSelect")
public class vagueSelect extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        String tmp = req.getParameter("tmp");
        String uid = req.getParameter("uid");

        List list =DB.executeQuery(" SELECT * FROM `user` u RIGHT JOIN friend f on u.account =f.friendid \n" +
                "WHERE userid = "+uid+" and friendid LIKE "+ "'%"+ tmp +"%'");

        resp.getWriter().print(new Gson().toJson(list));
    }
}
